package com.javaIO.demo1;

import java.io.*;

public class Test6 {

    /**
     * 字节数组读取图片
     *  BufferedInputStream BufferedOutputStream 字节缓冲流 底层基于字节数组  8192 ---8kb
     *
     */
    public static void main(String[] args) {
        FileInputStream inputStream = null;
        FileOutputStream outputStream = null;
        try {
            //1.读取内容
            inputStream = new FileInputStream("D:\\SoftDevelopment\\Java\\file\\图片.jpg");
            BufferedInputStream bufferedInputStream = new BufferedInputStream(inputStream);
            //2.写入内容
            outputStream = new FileOutputStream("D:\\SoftDevelopment\\Java\\file\\demo\\图片.jpg");
            BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(outputStream);


            byte[] bytes = new byte[1024];
            int len;
            while ((len = bufferedInputStream.read(bytes)) != -1) {
                //写入数据
                bufferedOutputStream.write(bytes, 0, len);
            }

        } catch (Exception e) {
            throw new RuntimeException(e);
        } finally {
            try {
                if (inputStream != null) {
                    inputStream.close();
                }
                if (outputStream != null) {
                    outputStream.close();
                }
            } catch (IOException e) {
                System.out.println(e.getMessage());
            }

        }

    }
}
